import Vue from "vue";
import VueRouter from "vue-router";
import LogIn from '@/components/login/LogIn.vue'
import min from "@/components/Min/MinX.vue"

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {
      path: '/',
      component: min,
    },
    {
      path: '/login',
      component: LogIn,
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.path === "/login") {
    next()
  } else {
    const token = localStorage.getItem("token")
    if (token) {
      next()
    } else {
      next("/login")
    }
  }

})
export default router
